package com.itclass.auth.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itclass.auth.pojo.db.SysUser;
import com.itclass.auth.pojo.dto.AuthUserDetails;
import com.itclass.auth.pojo.dto.UserDetailsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private SysUserService sysUserService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser user = sysUserService.queryUserByUsername(username);
        if (null == user) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        return AuthUserDetails.buildUserDetail(user);
    }
}
